package net.wanho.shop.controller;


import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import net.wanho.shop.po.Express;
import net.wanho.shop.service.ExpressService;
import net.wanho.shop.vo.AjaxResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;


/**
 * <p>
 * 快递表 前端控制器
 * </p>
 *
 * @author 猛虎王
 * @since 2024-12-24
 */
@Api(tags = "快递表接口")
@RestController
@RequestMapping("/express")
@RequiredArgsConstructor
public class ExpressController {

    private final ExpressService expressService;

    @ApiOperation("快递表分页查询")
    @GetMapping("/list")
    public AjaxResult findPage(@ApiParam("页码") @RequestParam(defaultValue = "1") int pagenum, @ApiParam("页大小") @RequestParam(defaultValue = "5") int pagesize, @ApiParam("查询条件") Express express) {
        PageInfo<Express> pageInfo = expressService.findPage(pagenum, pagesize, express);
        return AjaxResult.success(pageInfo);
    }

    @ApiOperation("根据主键查询快递表")
    @GetMapping("/{expressId}")
    public AjaxResult findById(@PathVariable Serializable expressId) {
        return AjaxResult.success(expressService.findById(expressId));
    }

    @ApiOperation("新增快递表")
    @PostMapping
    public AjaxResult add(@RequestBody Express express) {
        expressService.add(express);
        return AjaxResult.success();
    }

    @ApiOperation("修改快递表")
    @PutMapping
    public AjaxResult modify(@RequestBody Express express) {
        expressService.modify(express);
        return AjaxResult.success();
    }

    @ApiOperation("根据主键删除快递表")
    @DeleteMapping("/{expressId}")
    public AjaxResult removeById(@PathVariable Serializable expressId) {
        expressService.removeById(expressId);
        return AjaxResult.success();
    }

}
